package com.xuerhua.yxt.controller.sys;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xuerhua.yxt.common.RspResult;
import com.xuerhua.yxt.common.enums.Status;
import com.xuerhua.yxt.controller.BaseController;
import com.xuerhua.yxt.model.Grid;
import com.xuerhua.yxt.model.TermInfo;
import com.xuerhua.yxt.service.ITermInfoService;

@RequestMapping("sys/term")
@Controller
public class SysTermController extends BaseController {

	@Autowired
	private ITermInfoService termInfoService;
	
	@RequestMapping(value={"","/"})
	public String Index() {
		return "sys/term";
	}
	
	@RequestMapping("pageQuery")
	@ResponseBody Object pageQuery(int schoolId){
		try {
			List<TermInfo> list = termInfoService.selectList(schoolId);
			Grid grid = new Grid();
			grid.setRows(list);
			grid.setTotal(list.size());
			return grid;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@RequestMapping("addUpdate")
	@ResponseBody Object addUpdate(TermInfo record) {
		try {
			if(record.getId() == null) {
				termInfoService.insertSelective(record);
			}else {
				termInfoService.updateByPrimaryKeySelective(record);
			}
			return new RspResult(Status.SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new RspResult(Status.FAIL);
	}

	@RequestMapping("del")
	@ResponseBody Object del(String delIds) {
		try {
			termInfoService.delByPrimaryKey(
					Arrays.asList(delIds.split(",")));
			return new RspResult(Status.SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new RspResult(Status.FAIL);
	}
}
